package com.recipes.meg;

import android.app.Activity;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.widget.TextView;

public class ViewDescription extends Activity {
	// Declare variable to hold database helper and sqlite database
	SQLiteDatabase db;
	DatabaseHelper db_helper;
	
	// Declare variable to hold id of this recipe
	int id;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.view_description);
        
        // Instantiate new database helper
        db_helper = new DatabaseHelper(getApplicationContext());
        
        // Get id of this recipe from calling activity
        id = this.getIntent().getIntExtra("id", 1);
        
        // Instantiate title TextView
        TextView title = (TextView) findViewById(R.id.title);
        
        // Open the database for reading
        db = db_helper.getWritableDatabase();
        
        // Set the text of title to be the name of this recipe
        title.setText(db_helper.getName(db, id));
        
        // Close the database
        db.close();
                
        // Initialize description TextView
        TextView description_display = (TextView) findViewById(R.id.description);
        
        // Open the database for reading
        db = db_helper.getWritableDatabase();
        
        // Get the description of this recipe
        String description = db_helper.getDescription(db, id);
        
        // Close the database
        db.close();
        
        // Set the description text to display the description for this recipe
        description_display.setText(description);
    }
}
